{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"class Pile:\n def __init__(self):\n self.objets = []\n \n def est_vide(self):\n return len(self.objets) == 0\n \n def empiler(self, objet):\n self.objets.append(objet)\n \n def depiler(self):\n if self.est_vide():\n print(\"La pile est vide\")\n return None\n else:\n element = self.objets.pop()\n return element\n \n def trouver_sommet(self):\n if self.est_vide():\n print(\"La pile est vide\")\n return None\n else:\n self.objets[-1]\n \n def taille_pile(self):\n return len(self.objets)\n \n def __str__(self):\n for i in range(len(self.objets)-1,-1,-1):\n print(self.objets[i])\n return \"\"\n \np = Pile()\np.empiler(13)\np.empiler(25)\n\nprint(p)","execution_count":7,"outputs":[{"output_type":"stream","text":"25\n13\n\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"def bon_parenthesage(str):\n #à compléter\n pass\n \n#assert bon_parenthesage(\"((()())(()))\") == True\n#assert bon_parenthesage(\"())(()\") == False\n#assert bon_parenthesage(\"(())(()\") == False","execution_count":12,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def renverse(pile):\n #à compléter\n pass\n\ndef positifs(pile):\n #à compléter\n pass\n\n#assert renverse([1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1]\n#assert positifs([-1, 0, 5, -3, 4, -6, 10, 9, -8]) == [0, 5, 4, 10, 9]\n#assert positifs([-2]) == []","execution_count":13,"outputs":[]}],"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"}},"nbformat":4,"nbformat_minor":2}